import java.util.ArrayList;
import java.util.List;

//leetcode 77 组合
public class Test2 {
    List<List<Integer>> ret;
    List<Integer> path;
    int n, k;
    public List<List<Integer>> combine(int _n, int _k) {
        ret = new ArrayList<>();
        path = new ArrayList<>();
        n = _n;
        k = _k;
        dfs(1);
        return ret;
    }

    private void dfs(int pos) {
        if (path.size() == k) {
            ret.add(new ArrayList<>(path));
            return;
        }

        for (int i = pos; i <= n; i++) {
            path.add(i);
            dfs(i + 1);
            path.remove(path.size() - 1);
        }
    }
}
